<template>
	<view>

		<u-swipe-action>
			<u-swipe-action-item :options="options2" v-for="item in receivelist" :key="item.id" @click="toPages"
				:name="item.id">
				<view class="swipe-action u-border-top u-border-bottom">
					<view class="swipe-action__content">
						<u-cell-group>
							<u-cell :title="item.content" :value="item.record.nickname "
								:label="item.createtime"></u-cell>
						</u-cell-group>
					</view>
				</view>
			</u-swipe-action-item>
		</u-swipe-action>


		<u-button type="success" text="添加回访记录" color="#19BC9C" :customStyle="btnStyle1"
			@click="toPages('', 'add')"></u-button>
		<!-- 消息提示 -->
		<u-toast ref="uToast"></u-toast>
		<!-- 确认框 -->
		<u-modal :show="show" :content='content' :showCancelButton="true" @cancel="show = false"
			@confirm="confirm"></u-modal>




	</view>
</template>

<script>
	export default {
		data() {
			return {
				options2: [{
					text: '编辑',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				btnStyle1: {
					position: 'fixed',
					bottom: '0px',
					width: '100%',
					bottom: '0px'
				},
				LoginUser: {},
				receivelist: [],
				show:false,
				content:"确认是否删除当前回访记录？",
			}
		},
		onShow() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.getRevisitData()
			console.log(this.show)
		},
		methods: {
			toPages(item, msg) {
				if (msg == 'add') {
					uni.navigateTo({
						url: `/pages/business/revisit/add`
					})
				}
				if (item.index == 0) {
					uni.navigateTo({
						url: '/pages/business/revisit/edit?id=' + item.name
					})
				} if(item.index == 1) {
					this.show = true
					this.id = item.name

				}
			},
			async confirm() {
				this.show = false
				let result = await this.$u.api.business.VisitDel({
					id: this.id
				})
				if (result.code == 1) {
					// console.log(result.msg)
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
					})
					this.getRevisitData()
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg,
					})
				}
			},







			async getRevisitData() {
				let result = await this.$u.api.business.revisitlist({
					adminid: this.LoginUser.id ?? 1
				})
				if (result.code == 1) {
					this.receivelist = result.data
					console.log(this.receivelist)
				}
			},
		}
	}
</script>

<style>
</style>